home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
The Director Toolkit v1.0.adf
/
Programs
/
SineTable
/
PieChart
< prev
next >
Wrap
Text File
|
1987-02-25
|
5KB
|
238 lines
rem sine table example. Uses sine table to do pie chart
rem routine.
load 1,"ToolKit:pictures/blank.pic"
loadfont 1,8,"topaz.font"
setfont 1 :rem insure topaz 8 for labeling
rem these parameters can be adjusted dynamically if you like, or
rem you can set them to specific values and leave them
pxsize=80 :rem chart x size
pysize=pxsize*9/10 :rem chart y size
textclr=1 :rem text color
bordclr=5 :rem border color
startclr=4 :rem first color
nolabels=0 :rem set to 1 to inhibit text labeling
rem *******array locations *************
rem data pointers, make sure you have enough of these for your data
rem this represents the maximum number of slices allowable in the
rem piechart
data=0
dataa=10
datab=11
datac=12
datad=13
datae=14
dataf=15
datag=16
datah=17
lastdata=17
labelsz=21 :rem max label size=20 chars
title=lastdata+1 :rem array location of chart title
labela=title+labelsz :rem array location of first label
:rem should be one of these for each data element
labelb=labela+labelsz
labelc=labelb+labelsz
labeld=labelc+labelsz
labele=labeld+labelsz
labelf=labele+labelsz
labelg=labelf+labelsz
labelh=labelg+labelsz
sines=labelh+labelsz :rem sine table array location
array sines+92,2 :rem create the array
gosub 5020 :rem load in sine table
rem ********* initialization done ***********
rem initial center coordinate of a pie chart...
cx=160
cy=100
string "COMPUTER SALES",$(title)
5
rem setup the specific data and label for each slice for the chart
rem here's where you'd need to setup your data
elements=6 :rem number of slices
string "I.B.M.",$(labela)
@(dataa)=?400 :rem just use some random data for now.
string "Apollo",$(labelb)
@(datab)=?400
string "Amiga",$(labelc)
@(datac)=400 :rem make sure Amiga's always the biggest
string "Atari",$(labeld)
@(datad)=?200
string "MacIntosh",$(labele)
@(datae)=?400
string "Sun",$(labelf)
@(dataf)=?400
gosub 10 :rem draw the chart boxed and titled
rem move center point around the screen
cx=640-cx
if cx=160
cy=400-cy
if cy=100
pause 50
clear
endif
endif
goto 5 :rem do another chart at next location
rem ****** draw a chart ******
10
rem draw a box around graph
pen 1,3
move cx-160,cy-100
draw cx+159,cy-100
draw cx+159,cy+99
draw cx-160,cy+99
draw cx-160,cy-100
rem add title at top of graph
rem count characters in title
zzz=0
11 if @(title+zzz)
zzz=zzz+1
goto 11
endif
pen 1,1
move cx-zzz*4,cy-84
text $(title)
gosub 5100 :rem do the pie chart
return
rem *** pie chart routine ***
5100
rxsize=10000/pxsize :rem reciprocals
rysize=10000/pysize
pen 1,bordclr
offy=10
cy=cy+offy
ellipse cx,cy,pxsize,pysize
rem compute 100% total
total=0
for ttt=0 to elements-1
total=total+@(dataa+ttt)
next
rem draw and fill wedges
cl=startclr
degs=0
move cx,cy:draw cx,cy-pysize
for ttt=0 to elements-1
dist=(360*@(dataa+ttt)+total/2)/total
degs=degs+dist
deg=degs
gosub 5000 :rem sin
gosub 5010 :rem cos
move cx,cy
pen 1,bordclr
draw cx+sin/rxsize,cy-cos/rysize
deg=deg-dist/2
if dist>2 :rem don't fill if too small
gosub 5000
gosub 5010
pen 1,cl
cl=cl+1
fill 1,cx+sin/(rxsize+5),cy-cos/(rysize+5)
endif
next
if nolabels
return
endif
rem now do labels
degs=0
for ttt=0 to elements-1
dist=(360*@(dataa+ttt)+total/2)/total
degs=degs+dist
deg=degs-dist/2
gosub 5000
gosub 5010
rem count the characters in the label
label=labela+labelsz*ttt
zzz=0
5120 if @(label+zzz)
zzz=zzz+1
goto 5120
endif
drawmode 0
txtx=cx+sin/(9000/pxsize)-zzz*4
txty=cy-cos/(9000/pysize)
move txtx+2,txty+1
pen 1,0
text $(label)
move txtx,txty
pen 1,textclr
text $(label)
drawmode 1
next
cy=cy-offy
return
rem ********** Integer trig routines **************
rem sin routine
rem set deg= degree, returns sin= sin*10000
5000 sin=deg % 90
sina = (deg%360)/90
if sina=1 | sina=3
sin=90-sin
endif
sin=@(sines+sin)
if sina>1
sin = 0-sin
endif
return
rem cos routine
rem set deg= degree, returns cos= cos*10000
5010 cos=(deg+90) % 90
sina = ((deg+90)%360)/90
if sina=1 | sina=3
cos=90-cos
endif
cos=@(sines+cos)
if sina>1
cos = 0-cos
endif
return
rem **** load in sine table ****
5020
rem open sine table file
v=0
open v,"sinetab"
if 0=v
print "can't find sinetab"
end
endif
rem read in sine table
for i=0 to 90
read v,$(data),10
v = $(data)
@(sines+i)=v
next
return